<!doctype html>
<html lang="en" data-bs-theme="auto">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <title>栏目管理</title>

  <link href="/assets/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/assets/icons/bootstrap-icons.css">

  <link href="/css/dashboard.css" rel="stylesheet">
  <script src="/js/jquery.min.js"></script>  
</head>

<body>

  <div class="container-fluid">

    <h5 class="card-title mt-2">栏目管理</h5>
    <hr>
    <div class="row p-3">
      <div class="col-10">
        <table class="table table-bordered">
          <thead>
            <tr>
              <th scope="col">#</th>
              <th scope="col">名称</th>
              <th scope="col">url</th>
              <th scope="col">类型</th>
              <th scope="col">排序</th>
              <th scope="col">编辑</th>
            </tr>
          </thead>
          <tbody>
            <%c for(auto &a:obj["list"].as_array()){ %>
              <tr id="topicid_<%c echo<<a.second["id"].to_string(); %>">
                <td>
                  <%c echo<<a.second["id"].to_string(); %>
                </td>
                <td <%c if(a.second["parentid"].to_int()>0){ %>style="padding-left:<%c echo<<(a.second["level"].to_int()*15+15); %>px"<%c } %>>
                  <%c echo<<a.second["value"].as_string(); %>
                </td>
                <td>
                  <%c echo<<a.second["urlpath"].as_string(); %>
                </td>
                <td>
                  <%c 
                      switch(a.second["cateid"].to_int())
                      {
                            case 0:
                                 echo<<"图文内容";
                                 break;
                            case 1:
                                 echo<<"单页图文";
                                 break;
                            case 2:
                                 echo<<"多页图文";
                                 break;
                            case 3:
                                 echo<<"单页倒叙";
                                 break;   
                            case 4:
                                 echo<<"文档目录";
                                 break;
                            case 13:
                                 echo<<"博客类型";
                                 break;       
                      }
                  %>
                </td>
                <td>
                  <input type="text" class="form-inline topicsort col-md-3" id="title_<%c echo<<a.second["id"].to_string(); %>" name="title_<%c echo<<a.second["id"].to_string(); %>" value="<%c echo<<a.second["sortid"].to_string(); %>" onchange="updatetopic(<%c echo<<a.second["id"].to_string(); %>,this.value)">
                </td>
                <td>
                  <a href="/admin/edittopic?id=<%c echo<<a.second["id"].to_string(); %>">编辑</a>｜
                  <a href="/admin/deletetopic?id=<%c echo<<a.second["id"].to_string(); %>" onclick="return deletetopic(<%c echo<<a.second["id"].to_string(); %>)">删除</a>
                </td>
              </tr>
              <%c } %>
          </tbody>

        </table>
      </div>
    </div>

  </div>

  <script src="/assets/dist/js/bootstrap.bundle.min.js"></script>
  
  <script lang="javascript">
  
    function deletetopic(id)
    {
      if(confirm('是否删除?'))
      {          
          $.getJSON("/admin/deletetopic?id="+id,function(result){
                if(result.code==0)
                {
                
                     $("#topicid_"+id).remove();
                }
                
          });

      }
      return false;
    }
      function updatetopic(id,sortid)
    {
       $.getJSON("/admin/updatetopicsort?id="+id+"&sortid="+sortid,function(result){
                               
       });
    }
  </script>
</body>

</html>